﻿using System.Web.Mvc;
using System.Web.Routing;
using MyAMS.WebServer.ActionFilter;

namespace MyAMS.WebServer
{
    /// <summary>
    /// 基模块
    /// </summary>
    public abstract class BaseModule : IModule
    {
        #region IModule Members

        /// <summary>
        /// 获取功能名称
        /// </summary>
        /// <value></value>
        public abstract string Name { get; }

        /// <summary>
        /// 获取一个值, 该值指示当前实例是否已被加载
        /// </summary>
        /// <value></value>
        public bool IsLoaded { get; protected set; }

        /// <summary>
        /// 加载时被调用
        /// </summary>
        public virtual void OnLoading()
        {
        }

        /// <summary>
        /// 加载被忽略的路由
        /// </summary>
        /// <param name="routes"></param>
        public virtual void LoadIgnoredRoutes(RouteCollection routes)
        {
        }

        /// <summary>
        /// 加载路由
        /// </summary>
        /// <param name="routes"></param>
        public virtual void LoadRoutes(RouteCollection routes)
        {
        }

        /// <summary>
        /// 加载模糊路由
        /// </summary>
        /// <param name="routes"></param>
        public virtual void LoadCatchAllRoutes(RouteCollection routes)
        {
        }

        /// <summary>
        /// 加载视图引擎
        /// </summary>
        /// <param name="viewEngines">视图引擎</param>
        public virtual void LoadViewEngines(ViewEngineCollection viewEngines)
        {
        }

        /// <summary>
        /// 加载动作过滤器
        /// </summary>
        /// <param name="filterRegistry"></param>
        public virtual void LoadActionFilters(IActionFilterRegistry filterRegistry)
        {
        }

        /// <summary>
        /// 加载模型绑定器
        /// </summary>
        /// <param name="modelBinders"></param>
        public virtual void LoadModelBinders(ModelBinderDictionary modelBinders)
        {
        }

        /// <summary>
        /// 加载完毕后被调用
        /// </summary>
        public virtual void OnLoaded()
        {
            IsLoaded = true;
        }

        /// <summary>
        /// 卸载路由注册
        /// </summary>
        /// <param name="routes"></param>
        public virtual void UnLoadRoutes(RouteCollection routes)
        {
        }

        /// <summary>
        /// 卸载
        /// </summary>
        public virtual void UnLoad()
        {
            IsLoaded = false;
        }

        #endregion
    }
}
